package com.rental.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rental.common.login.GetIdByToken;
import com.rental.common.result.AjaxResult;
import com.rental.common.util.AuthContextHolder;
import com.rental.model.form.house.SubletHouseAddForm;
import com.rental.model.form.house.SubletHousePageForm;
import com.rental.model.vo.house.SubletHouseInfoVo;
import com.rental.model.vo.house.SubletHousePageVo;
import com.rental.web.service.SubletHouseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "转租房屋模块")
@RequestMapping("/house")
public class HouseController {
    @Autowired
    private SubletHouseService subletHouseService;

    @Operation(summary = "转租房屋页面")
    @PostMapping("/getSubletHousePage/{page}/{size}")
    public AjaxResult<Page<SubletHousePageVo>> getSubletHousePage(@PathVariable("page") Integer page,
                                                           @PathVariable("size") Integer size,
                                                           @RequestBody SubletHousePageForm subletHousePageForm) {
        return AjaxResult.success(subletHouseService.getSubletHousePage(page, size, subletHousePageForm));
    }


    @GetIdByToken
    @Operation(summary = "转租房屋详情")
    @GetMapping("/{id}")
    public AjaxResult<SubletHouseInfoVo> getSubletHouseInfoById(@PathVariable("id") Long id) {
        return AjaxResult.success(subletHouseService.getSubletHouseInfoById(id, AuthContextHolder.getUserId()));
    }

    @GetIdByToken
    @Operation(summary = "发布转租房屋")
    @PostMapping("/addSubletHouse")
    public AjaxResult<Boolean> addSubletHouse(@RequestBody SubletHouseAddForm subletHouseAddForm) {
        subletHouseAddForm.setUid(AuthContextHolder.getUserId());
        Boolean b = subletHouseService.addSubletHouse(subletHouseAddForm);
        return AjaxResult.success(b);
    }

    @GetIdByToken
    @Operation(summary = "下架房屋")
    @GetMapping("/downHouse/{id}")
    public AjaxResult<Boolean> downHouse(@PathVariable("id") Long id) {
        return AjaxResult.success(subletHouseService.downHouse(id, AuthContextHolder.getUserId()));
    }

    @GetIdByToken
    @Operation(summary = "获取联系微信")
    @GetMapping("/getContactWechat/{id}")
    public AjaxResult<String> getContactWechat(@PathVariable("id") Long id) {
        return AjaxResult.success(subletHouseService.getContactWechat(id, AuthContextHolder.getUserId()));
    }

    @GetIdByToken
    @Operation(summary = "获取联系电话")
    @GetMapping("/getContactPhone/{id}")
    public AjaxResult<String> getContactPhone(@PathVariable("id") Long id) {
        return AjaxResult.success(subletHouseService.getContactPhone(id, AuthContextHolder.getUserId()));
    }

    @GetIdByToken
    @Operation(summary = "删除房屋")
    @DeleteMapping("/{id}")
    public AjaxResult<Boolean> deleteSubletHouse(@PathVariable("id") Long id) {
        return AjaxResult.success(subletHouseService.deleteSubletHouse(id, AuthContextHolder.getUserId()));
    }

    @GetIdByToken
    @Operation(summary = "收藏转租房屋")
    @GetMapping("/collect/{id}")
    public AjaxResult<Boolean> collectHouse(@PathVariable("id") Long id) {
        return AjaxResult.success(subletHouseService.collectHouse(id, AuthContextHolder.getUserId()));
    }

    @GetIdByToken
    @Operation(summary = "取消收藏转租房屋")
    @DeleteMapping("/collect/{id}")
    public AjaxResult<Boolean> cancelCollectHouse(@PathVariable("id") Long id) {
        return AjaxResult.success(subletHouseService.cancelCollectHouse(id, AuthContextHolder.getUserId()));
    }

    @GetIdByToken
    @Operation(summary = "举报")
    @GetMapping("/accusation/{id}")
    public AjaxResult<Integer> accusation(@PathVariable("id") Long id) {
        return AjaxResult.success(subletHouseService.accusation(id, AuthContextHolder.getUserId()));
    }
}
